<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Chatbox extends CI_Controller {
    function  __construct(){
        parent::__construct();
        $this->load->helper('thoigian'); 
    }
    function index(){
        $chat= '';
        $this->load->view('chatbox/chatbox',
            array(                
                'chatc'=>$chat
            )
            );
    }
    function ndchatbox(){
        $data = $this->Home_model->get_data('chatbox','',array(100),array('id','DESC'));        
        if(!empty($data)){
            foreach ($data as $data){
                echo $data->username=="admin"?'<b style="color:red;">':'<b style="color:#1565d2;">';
                echo $data->username;
                echo '</b>: ';
                echo $data->content;
                echo '<br />';
                
            }
        }
        
    }
    function adddata(){
        if($_POST){
            $this->db->insert(
                'chatbox',
                array(
                    'username'=>$this->session->userdata('user')->username,
                    'time'=>time(),
                    'content'=>$this->input->post('data',true)
                )            
            );
        }
    }
    function topcredit(){
        $this->db->limit(50);
        $this->db->order_by('id','DESC');
        $this->db->select(
                            'credit.*,
                            users.username,
                            offer.title,
                            network.title as nettitle                            
                            ');
        $this->db->from('credit');
        $this->db->join('users', 'users.id = credit.iduser','left'); 
        $this->db->join('offer', 'offer.id = credit.idoff','left');   
        $this->db->join('network', 'network.id = credit.idnet','left');     
        $topc = $this->db->get()->result();        
        $this->load->view('chatbox/topcredit',array('topcredit'=>$topc));
    }
    
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */